<template>
  <el-dialog
    width="1200px"
    :title="$t('自派送包裹列表')"
    destroy-on-close
    append-to-body
    :visible.sync="show"
    :before-close="cancel"
  >
    <!-- <el-row>
      <el-form :model="queryParams" ref="queryForm" size="small" inline v-show="showSearch">
        <el-form-item prop="packageNo">
          <el-input
            :placeholder="$t('包裹号')"
            v-model="queryParams.packageNo"
            clearable
            @keyup.enter.native="getList"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">
            {{ $t('搜索') }}
          </el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
            {{ $t('重置') }}
          </el-button>
        </el-form-item>
      </el-form>
    </el-row> -->
    <el-table :height="calTableHeight() - 100" ref="TableRef" :data="tableData">
      <!-- 包裹号 地址 收货人 行程 车辆 操作 -->
      <el-table-column show-overflow-tooltip align="center" :label="$t('包裹号')" prop="packageNo" />
      <el-table-column show-overflow-tooltip align="center" :label="$t('地址')" prop="address" />
      <el-table-column show-overflow-tooltip align="center" :label="$t('收货人')" prop="receiveName" />
      <el-table-column show-overflow-tooltip align="center" :label="$t('行程')" prop="routeNo" />
      <el-table-column show-overflow-tooltip align="center" :label="$t('序号')" prop="routePolyLineIndex" />
      <el-table-column show-overflow-tooltip align="center" :label="$t('车辆')" prop="vehicleName" />
      <el-table-column show-overflow-tooltip align="center" :label="$t('操作')" fixed="right" width="200">
        <template #default="{ row }">
          <el-button type="text" @click="handleDeletePackage(row)">{{ $t('删除自派送并计算首尾路线') }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div slot="footer">
      <el-button @click="cancel">
        {{ $t('关闭') }}
      </el-button>
    </div>
  </el-dialog>
</template>
<script>
// import { api } from '@/api/**'
import { getGoogleRouteShipmentsList, deleteGoogleRouteShipments } from '@/api/orderManage/batchDispatch'

export default {
  props: {
    /**
     * formData
     */
    formData: {
      type: Object,
      default: () => ({}),
    },
    /**
     * type
     */
    type: {
      type: String,
    },
    /**
     * 控制显示隐藏
     */
    show: {
      type: Boolean,
      required: true,
      default: false,
    },
  },
  data() {
    return {
      /**显示搜索条件 */
      showSearch: true,
      /**表格选中项 */
      tableCheck: [],
      /**表格数据 */
      tableData: [],
      loading: false,
      /**总条数 */
      total: 0,
      /**分页相关查询参数 */
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        packageNo: '',
      },
    }
  },
  computed: {},
  watch: {
    show: function (newValue) {
      if (newValue) {
        this.getList()
      }
    },
  },
  methods: {
    handleDeletePackage(row) {
      this.$confirm(this.$t('确认删除?'), this.$t('提示'), {
        type: 'warning',
      }).then(() => {
        deleteGoogleRouteShipments(row.id).then((res) => {
          const { code, data, msg } = res
          if (code === 200) {
            this.$message({ type: 'success', message: msg })
            this.getList()
          }
        })
      })
    },
    getList() {
      this.loading = true
      getGoogleRouteShipmentsList({
        ...this.queryParams,
        batchId: this.formData.id,
      })
        .then((res) => {
          this.tableData = res.rows
          this.total = res.total
        })
        .finally(() => (this.loading = false))
    },

    cancel() {
      this.$emit('update:show', false)
      this.$emit('getList')
    },
    /** 重置按钮操作 */
    resetQuery() {
      Object.keys(this.queryParams).forEach((key) => (this.queryParams[key] = null))
      this.queryParams.pageNum = 1
      this.queryParams.pageSize = 10
      this.getList()
    },
  },
}
</script>
<style scoped lang="scss"></style>
